<?php
/* $tel = trim($_REQUEST['tel']);
$content = trim($_REQUEST['sms']);
$hqsms = new HongQun_SMS();
$user_key = ($_REQUEST['user_key'])?'EHwXQXg2qrdPAcbu4mTZQ==':'qFBoctUIM2ZZc36kW3pbIA==';
// $sendsms = $hqsms->doSendSMS($tel,$content,$user_key);
$sendsms = $hqsms->getSmsBalance();
// echo $sendsms;
class HongQun_SMS{
	private $post_url= 'http://222.77.181.44:8080/smsSystem/action/interface_deal/InterfaceDealAction.shtml?postMethod=';	
	//发送短信
	public function doSendSMS($tel,$content,$user_key){
		$method = 'doSendSMS';
		$request = <<<XML
<?xml version='1.0' encoding='UTF-8'?>
  <reqinfo>
    <user_key>{$user_key}</user_key>
    <mobiles>{$tel}</mobiles>   
	<sms_content>{$content}</sms_content>
    <send_time></send_time>
  </reqinfo>
XML;
		$response = $this->post($method,$request);
		// $this->getSmsBalance(); //检查剩余条数
		if(strlen($response)>=36)	return 100;
		else	return 101;
	}
	
	public function getSmsBalance(){
		$method = 'getSmsBalance';
		$request=<<<XML
<?xml version='1.0' encoding='UTF-8'?>
  <reqinfo>
    <user_key>EHwXQXg2qrdPAcbu4mTZQ==</user_key>
  </reqinfo>
XML;
		$response = $this->post($method,$request);
		print_r($response);
		// if(is_numeric($response) && $response < 1000))
			// $this->doSendSMS("18060610535","鸿群短信剩余条数".$response."，请联系鸿群尽快充值，否则此短信会一直发送");
	}
	  
	
	public function post($method,$request){
		$post_url = $this->post_url.$method;
		$ch = curl_init();//打开
		curl_setopt($ch, CURLOPT_POST, true);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml')); 
		curl_setopt($ch, CURLOPT_URL, $post_url);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
		$response  = curl_exec($ch);
		curl_close($ch);//关闭 
		return $response;
	}  
	
}   */
?>